package com.ymatou.promotion.api.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.promotion.api.parameter.CouponBatchBean;
import com.ymatou.promotion.api.parameter.CouponDetail;
import com.ymatou.promotion.api.parameter.CouponValueInfoBean;
import com.ymatou.promotion.api.parameter.CreateSellerCouponBean;
import com.ymatou.promotion.api.parameter.GetCouponsByBatchCodeBean;
import com.ymatou.promotion.api.service.CreateSellerCouponCall;
import com.ymatou.promotion.api.service.GetCouponsByBatchCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.database.model.YmtCoupon;
import com.ymttest.database.model.YmtCouponBatch;
import com.ymttest.database.model.YmtCouponPrivateUserBound;
import com.ymttest.database.model.YmtCouponScenario;
import com.ymttest.database.model.YmtCouponSetting;
import com.ymttest.database.model.YmtCouponValue;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
import com.ymttest.database.sqlwapper.YmtCouponScenarioWapper;
import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
import com.ymttest.database.sqlwapper.YmtCouponValueWapper;
import com.ymttest.database.sqlwapper.YmtCouponWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

/**
 * 获取批次中的优惠券列表
 *
 * @author chenjiazhu
 */
@TestSuite
public class Ts_GetCouponsByBatchCode {
    private static GetCouponsByBatchCodeBean getcouponsbybatchcodeBean;
    private static GetCouponsByBatchCodeCall getcouponsbybatchcodeCall;

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("获取批次中的优惠券列表");
    }

    @Before
    public void caseUp() {
        getcouponsbybatchcodeBean = new GetCouponsByBatchCodeBean();
        getcouponsbybatchcodeCall = new GetCouponsByBatchCodeCall();
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(getcouponsbybatchcodeCall.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_001() {
        Logger.start(true, "获取全场优惠券批次中的优惠券列表");
        try {
            String batchCode = new CouponCallService().createSellerDefaultCoupon();

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_002() {
        Logger.start(true, "获取商品优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerProductCoupon();

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_003() {
        Logger.start(true, "获取洋码头PC端全场优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerCoupon("1");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_004() {
        Logger.start(true, "获取洋码头WAP端全场优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerCoupon("2");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_005() {
        Logger.start(true, "获取洋码头APP全场优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerCoupon("3");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_006() {
        Logger.start(true, "获取神器APP全场优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerCoupon("4");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_007() {
        Logger.start(true, "获取神器WAP全场优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerCoupon("5");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_008() {
        Logger.start(true, "获取洋码头PC端商品优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerProductCoupon("1");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_009() {
        Logger.start(true, "获取洋码头WAP端商品优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerProductCoupon("2");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();


        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_010() {
        Logger.start(true, "获取洋码头APP商品优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerProductCoupon("3");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();


        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_011() {
        Logger.start(true, "获取神器APP商品优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerProductCoupon("4");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_012() {
        Logger.start(true, "获取神器WAP商品优惠券批次中的优惠券列表");
        try {

            String batchCode = new CouponCallService().createSellerProductCoupon("5");

            setGetCouponsByBatchCode(batchCode);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            VerifyReturn();

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_013() {
        Logger.start(false, "BatchCode空");
        try {

            String batchCode = new CouponCallService().createSellerDefaultCoupon();

            setGetCouponsByBatchCode(batchCode);
            getcouponsbybatchcodeBean.setBatchCode(null);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            Logger.verifyEquals("201", getcouponsbybatchcodeCall.getCode(), "验证返回code");
            Logger.verifyEquals("-1", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
            Logger.verifyEquals("-1:未查询到优惠券详情信息", getcouponsbybatchcodeCall.getMsg(), "验证返回MessageText");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_014() {
        Logger.start(false, "验证CreateUserId空时返回报错");
        try {

            String batchCode = new CouponCallService().createSellerDefaultCoupon();

            setGetCouponsByBatchCode(batchCode);
            getcouponsbybatchcodeBean.setCreateUserId(0);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            Logger.verifyEquals("200", getcouponsbybatchcodeCall.getCode(), "验证返回code,不是很明白，为啥能返回正确");
            Logger.verifyEquals("0", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
            Logger.verifyEquals("获取优惠券详情列表，总记录数1", getcouponsbybatchcodeCall.getMessageText(), "验证返回MessageText");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_015() {
        Logger.start(false, "验证BatchCode与CreateUserId不匹配时返回报错");
        try {

            String batchCode = new CouponCallService().createSellerDefaultCoupon();

            setGetCouponsByBatchCode(batchCode);
            getcouponsbybatchcodeBean.setCreateUserId(1234);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            Logger.verifyEquals("201", getcouponsbybatchcodeCall.getCode(), "验证返回code");
            Logger.verifyEquals("-1", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
            Logger.verifyEquals("-1:未查询到优惠券详情信息", getcouponsbybatchcodeCall.getMsg(), "验证返回MessageText");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_016() {
        Logger.start(false, "验证PageSize空时");
        try {
            String batchCode = new CouponCallService().createSellerDefaultCoupon();

            setGetCouponsByBatchCode(batchCode);
            getcouponsbybatchcodeBean.setPageSize(0);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            Logger.verifyEquals("200", getcouponsbybatchcodeCall.getCode(), "验证返回code,不是很明白，为啥能返回正确");
            Logger.verifyEquals("0", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
            Logger.verifyEquals("获取优惠券详情列表，总记录数1", getcouponsbybatchcodeCall.getMessageText(), "验证返回MessageText");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_017() {
        Logger.start(false, "验证CurPage空取默认值");
        try {
            String batchCode = new CouponCallService().createSellerDefaultCoupon();

            setGetCouponsByBatchCode(batchCode);
            getcouponsbybatchcodeBean.setCurPage(0);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            Logger.verifyEquals("200", getcouponsbybatchcodeCall.getCode(), "验证返回code,不是很明白，为啥能返回正确");
            Logger.verifyEquals("0", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
            Logger.verifyEquals("获取优惠券详情列表，总记录数1", getcouponsbybatchcodeCall.getMessageText(), "验证返回MessageText");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_018() {
        Logger.start(false, "验证BatchCode不存在时返回报错");
        try {

            getcouponsbybatchcodeBean.setBatchCode("1332");
            getcouponsbybatchcodeBean.setCreateUserId(Integer.valueOf(EnvSetup.getData("SellerId")));
            getcouponsbybatchcodeBean.setPageSize(1);
            getcouponsbybatchcodeBean.setCurPage(1);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            Logger.verifyEquals("201", getcouponsbybatchcodeCall.getCode(), "验证返回code");
            Logger.verifyEquals("-1", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
            Logger.verifyEquals("-1:未查询到优惠券详情信息", getcouponsbybatchcodeCall.getMsg(), "验证返回MessageText");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_GetCouponsByBatchCode_019() {
        Logger.start(true, "获取多张优惠券");
        try {
            CreateSellerCouponBean createsellercouponBean = new CreateSellerCouponBean();
            CreateSellerCouponCall createsellercouponCall = new CreateSellerCouponCall();

            CouponBatchBean couponBatchBean = new CouponBatchBean();

            couponBatchBean.setSellerId(Integer.valueOf(EnvSetup.getData("SellerId")));
            couponBatchBean.setCouponName("自动化创建优惠券名称" + TestDataManager.getRandomNum(5));
            couponBatchBean.setCouponDesc("自动化创建优惠券描述" + TestDataManager.getRandomNum(10));

            List<CouponValueInfoBean> couponValues = new ArrayList<CouponValueInfoBean>();

            CouponValueInfoBean couponValue = new CouponValueInfoBean();

            couponValue.setOrderValue(new BigDecimal(2));
            couponValue.setCouponValue(new BigDecimal(1));
            couponValue.setCouponUseType(1);

            couponValues.add(couponValue);

            couponBatchBean.setCouponValues(couponValues);
            couponBatchBean.setMaxSendNum(10);
            couponBatchBean.setUserMaxReceiveNum(10);

            Date dNow = new Date(); // 当前时间
            Date dBefore = new Date();
            Date dAfter = new Date();

            Calendar calendar1 = Calendar.getInstance(); // 得到日历
            calendar1.setTime(dNow);// 把当前时间赋给日历
            calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
            dBefore = calendar1.getTime(); // 得到前一天的时间

            Calendar calendar2 = Calendar.getInstance(); // 得到日历
            calendar2.setTime(dNow);// 把当前时间赋给日历
            calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
            dAfter = calendar2.getTime(); // 得到前一天的时间

            couponBatchBean.setValidStart(dBefore);
            couponBatchBean.setValidEnd(dAfter);

            couponBatchBean.setScenarioType(1);

            createsellercouponBean.setCouponBatchBean(couponBatchBean);
            createsellercouponCall.setData(createsellercouponBean);
            createsellercouponCall.callService();

            String batchCode = createsellercouponCall.getBatchCode();

            List<String> couponCodesList = new ArrayList<String>();
            for (int i = 0; i < 10; i++)
            {
                couponCodesList.add(new CouponCallService().receiveCouponInfo(batchCode,
                        Integer.valueOf(EnvSetup.getData("SellerId"))));
            }

            getcouponsbybatchcodeBean.setBatchCode(batchCode);
            getcouponsbybatchcodeBean.setCreateUserId(Integer.valueOf(EnvSetup.getData("SellerId")));
            getcouponsbybatchcodeBean.setPageSize(100);
            getcouponsbybatchcodeBean.setCurPage(1);

            getcouponsbybatchcodeCall.setData(getcouponsbybatchcodeBean);
            getcouponsbybatchcodeCall.callService();

            List<CouponDetail> couponlist = getcouponsbybatchcodeCall.getCouponsByBatchCodeData().getCouponDetails();

            Logger.verifyEquals("200", getcouponsbybatchcodeCall.getCode(), "验证返回code");
            Logger.verifyEquals("0", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
            Logger.verifyEquals("获取优惠券详情列表，总记录数10", getcouponsbybatchcodeCall.getMessageText(), "验证返回MessageText");

            int length = couponCodesList.size();
            for (int i = 0; i < length; i++) {
                Logger.verifyEquals(couponCodesList.get(length - i - 1),
                        ((CouponDetail) couponlist.get(i)).getCouponCode(), "验证返回code");
                Logger.verifyEquals(Integer.parseInt(EnvSetup.getData("SellerId")),
                        ((CouponDetail) couponlist.get(i)).getUserId(), "验证返回code");
                Logger.verifyEquals(EnvSetup.getData("SellerName"), ((CouponDetail) couponlist.get(i)).getUserName(),
                        "验证返回code");

            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    /**
     * 根据传入batchCode设置请求bean
     * 
     * @param batchCode
     * @throws NumberFormatException
     * @throws ClientProtocolException
     * @throws IOException
     */
    private void setGetCouponsByBatchCode(String batchCode) throws NumberFormatException, ClientProtocolException,
            IOException
    {
        new CouponCallService().receiveCouponInfo(batchCode, Integer.valueOf(EnvSetup.getData("SellerId")));
        getcouponsbybatchcodeBean.setBatchCode(batchCode);
        getcouponsbybatchcodeBean.setCreateUserId(Integer.valueOf(EnvSetup.getData("SellerId")));
        getcouponsbybatchcodeBean.setPageSize(1);
        getcouponsbybatchcodeBean.setCurPage(1);

    }

    private void VerifyReturn()
    {
        Logger.verifyEquals("200", getcouponsbybatchcodeCall.getCode(), "验证返回code");
        Logger.verifyEquals("0", getcouponsbybatchcodeCall.getBCode(), "验证返回Bcode");
        Logger.verifyEquals("获取优惠券详情列表，总记录数1", getcouponsbybatchcodeCall.getMessageText(), "验证返回MessageText");

        String batchCode = getcouponsbybatchcodeBean.getBatchCode();

        YmtCouponBatch couponBatch = new YmtCouponBatchWapper().selectBysBatchCode(batchCode).get(0);
        YmtCouponValue couponValue =
                new YmtCouponValueWapper().selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
        YmtCouponSetting couponSetting =
                new YmtCouponSettingWapper().selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
        YmtCouponScenario couponScenario =
                new YmtCouponScenarioWapper().selectByiCouponScenarioId(couponSetting.getiScenarioId()).get(0);

        YmtCoupon coupon = new YmtCouponWapper().selectByiBatchId(couponBatch.getiBatchId()).get(0);
        YmtCouponPrivateUserBound couponPrivateUserBound =
                new YmtCouponPrivateUserBoundWapper().selectBysCouponId(coupon.getsCouponId()).get(0);

        Logger.verifyEquals(couponBatch.getsBatchCode(), getcouponsbybatchcodeCall.getBatchCode1(),
                "验证返回BatchCode与数据库Ymt_CouponBatch表中一致");
        Logger.verifyEquals(couponBatch.getsCouponName(), getcouponsbybatchcodeCall.getCouponName(),
                "验证返回CouponName与数据库Ymt_CouponBatch表中一致");

        Logger.verifyEquals(couponBatch.getiCouponTotalNum(),
                Integer.parseInt(getcouponsbybatchcodeCall.getMaxSendNum()), "验证返回MaxSendNum与数据库Ymt_CouponBatch表中一致");
        Logger.verifyEquals(couponSetting.getiReceiveCount(),
                Integer.parseInt(getcouponsbybatchcodeCall.getReceiveNum()), "验证返回ReceiveNum与数据库Ymt_CouponSetting表中一致");
        Logger.verifyEquals(couponSetting.getiCouponUseCount() - couponPrivateUserBound.getiCouponUsedCount(),
                Integer.parseInt(getcouponsbybatchcodeCall.getUsedNum()), "验证验证返回UsedNum与数据库Ymt_CouponSetting表中一致");

        Logger.verifyEquals(getDateString(couponSetting.getdValidStart()), getcouponsbybatchcodeCall.getValidBegin1(),
                "验证返回ValidBegin与数据库Ymt_CouponSetting表中一致");
        Logger.verifyEquals(getDateString(couponSetting.getdValidEnd()), getcouponsbybatchcodeCall.getValidEnd1(),
                "验证返回ValidEnd与数据库Ymt_CouponSetting表中一致");

        Logger.verifyEquals(
                couponBatch.getdInvalidTime() == null ? "null" : getDateString(couponBatch.getdInvalidTime()),
                getcouponsbybatchcodeCall.getInvalidTime(), "验证返回InvalidTime与数据库Ymt_CouponBatch表中一致");
        Logger.verifyEquals(couponBatch.getbInvalidStatus() == false ? "false" : "true",
                getcouponsbybatchcodeCall.getInvalidStatus(), "验证返回InvalidStatus与数据库Ymt_CouponBatch表中一致");

        Logger.verifyEquals("1", getcouponsbybatchcodeCall.getTotals(), "验证返回Totals");

        // 验证CouponDetails
        Logger.verifyEquals(couponPrivateUserBound.getsCouponCode(), getcouponsbybatchcodeCall.getCouponCode(),
                "验证返回CouponCode与数据库表Ymt_CouponPrivateUserBound中一致");

        // 存储过程中，没找到哪取的值
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getBatchCode2(), "验证返回BatchCode");
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getMinOrderAmount(), "验证返回MinOrderAmount");
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getCouponValue(), "验证返回CouponValue");
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getCouponType(), "验证返回CouponType");
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getCouponUseType(), "验证返回CouponUseType");
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getPlatformType(), "验证返回PlatformType");

        Logger.verifyEquals(getDateString(coupon.getdValidStart()), getcouponsbybatchcodeCall.getValidBegin2(),
                "验证返回ValidBegin与数据库表ymt_coupon一致");
        Logger.verifyEquals(getDateString(coupon.getdValidEnd()), getcouponsbybatchcodeCall.getValidEnd2(),
                "验证返回ValidEnd与数据库表ymt_coupon一致");

        // 存储过程中，没找到哪取的值
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getRemainder(), "验证返回Remainder");
        // 太复杂
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getCouponState(), "验证返回CouponState");

        Logger.verifyEquals(EnvSetup.getData("SellerId"), getcouponsbybatchcodeCall.getUserId(), "验证返回UserName正确性");
        Logger.verifyEquals(EnvSetup.getData("SellerName"), getcouponsbybatchcodeCall.getUserName(), "验证返回UserName正确性");

        // 存储过程中，没找到哪取的值
        // Logger.verifyEquals(couponBatch.getsBatchCode(),
        // getcouponsbybatchcodeCall.getCreateType(), "验证返回CreateType");

    }

    private String getDateString(java.util.Date date)
    {
        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");

        return formatter1.format(date) + "T" + formatter2.format(date);
    }
}
